//
//  ZGSCartoonfriendModel.m
//  MapleLeaf
//
//  Created by 邝子涵 on 15/12/1.
//  Copyright © 2015年 AntennaBabyTeam. All rights reserved.
//

#import "ZGSCartoonfriendModel.h"

@implementation ZGSCartoonfriendModel

- (instancetype)initWithDataSource:(NSDictionary *)dic{
    self = [super init];
    if (self) {
        [self setValuesForKeysWithDictionary:dic];
    }
    return self;
}

// 赋值纠错
- (id)valueForUndefinedKey:(NSString *)key{
    return nil;
}

// 取值纠错
- (void)setValue:(id)value forUndefinedKey:(NSString *)key{
    if ([key isEqualToString:@"data"]) {
        NSDictionary *dic = value;
        
        // 定义一个可变数组承接转化后的model
        NSMutableArray *mArr = [NSMutableArray arrayWithCapacity:0];
        
        for (NSDictionary *tempDic in dic[@"list"]) {
            // 实例化model
            ZGSCartoonfriendSonModel *model = [[ZGSCartoonfriendSonModel alloc] init];
            // 使用KVC的方法给小model赋值
            [model setValuesForKeysWithDictionary:tempDic];
            // 单独解析图片
            [model setValue:[[tempDic[@"pic"] componentsSeparatedByString:@","] objectAtIndex:0] forKey:@"pic"];
            // 添加
            [mArr addObject:model];
        }
        
        // 这样完成字典转换model
        self.dataArray = mArr;
    }
    
}


@end
